home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
ooptut34.zip
/
TP
/
OOPTUTOR
/
TVISION.TXT
< prev
next >
Wrap
Text File
|
1993-06-12
|
22KB
|
444 lines
TURBO VISION.
-------------
Introduction.
-------------
Since Turbo Vision makes use of object-oriented techniques, including
inheritance and polymorphism, it is necessary to be completely familiar
with object-oriented programming. Furthermore the object instances are
dynamically allocated on the heap, so that familiarity with pointers and
dynamic variables is also essential. The extended syntax of the 'New'
procedure, which allows the allocation of space on the heap for an object
and its initialization within the one procedure must also be appreciated.
This new procedure is now invoked with two parameters, the pointer name as
the first parameter and the constructor invocation as the second parameter.
All these topics are covered in the notes on Advanced Data Structures and
Object-Oriented Programming.
In OOP parlance, an 'object type' is an abstraction that provides a
template for specific objects, which are themselves called 'instances' of
that object type. In Turbo Vision, the templates or object types all start
with the letter T, whilst all pointer types start with the letter P. Both
the object instances and the actual pointer variables have names
appropriate to the circumstances of use. Thus typical variable
declarations are:
VAR
Window: PDemoWindow; {see page 32 of the Turbo Vision Guide}
R: TRect;
The extended syntax of 'New' also allows it to be used as a function,
returning a pointer value. An example taken from page 32 of the Guide is:
Window := New(PDemoWindow, Init( R, 'Demo Window',WinCount));
| | / \ | |
Pointer Pointer Constructor Object Title Number
variable type invocation of type
TRect
Thus Window is a pointer of type PDemoWindow, which itself has been
previously declared as:
TYPE
PDemoWindow = ^TDemoWindow; { a pointer to type TDemoWindow }
TDemoWindow = OBJECT(TWindow) { a simple user-defined descendant }
END; { object of TWindow }
Hence Window points to an object type TDemoWindow, which inherits the
fields and methods from the ancestor object type TWindow (see pages
321-325). The 'Init' method for TWindow is a static method and is defined
on page 322. Three parameters are required, namely the bounds, a title and
a number.
The bounds are given by the parameter R, which is of type TRect (see page
278), whose data fields define the corners at the top left (A) and the
bottom right (B) of the rectangle. One of TRect's (static) methods is the
Assign procedure, which gives the coordinates to the points A and B as XA,
YA, XB, YB (each of type integer).
The assignment is made using the conventional dot notation, so as on page
32 the statement is:
R.Assign(0, 0, 26, 7); { set initial size and position }
The second parameter to a TWindow initialization is a literal title (in
single quotes) and this will be displayed at the top of the window, along
with the third parameter, the WinCount number.
The declarations and assignments shown in the above few paragraphs
illustrate the existence in Turbo Vision of predefined objects, each with
its appropriate fields and methods, some of which are static and may be
used directly, whilst others are virtual and may be overridden.
The way in which objects inherit from ancestor types is indicated in the
Turbo Vision object hierarchy shown on page 66 of the Turbo Vision Guide.
It is seen that the object type TWindow referred to in the preceding
paragraphs is part of this hierarchy tree:
TObject --- TView -----
| |--
| |--
| |--
| |-- TGroup -----
|--
|-- TWindow -----
|--
Each of these object types is sufficiently defined for any user application
in Chapter 13 'Object reference' on pages 205-325. The actual code is only
accessible as a compiled unit (.TPU file), the name of which is also shown
in the reference. Thus the 'root' ancestor TObject (pages 267-8) is shown
to be part of OBJECTS.TPU, to have no fields and just three methods, Init,
Free (both static) and Done (virtual).
Apart from TPoint and TRect (see below) all Turbo Vision's standard objects
are ultimately derived from TObject. Any object that uses Turbo Vision's
streams facilities must trace its ancestry back to TObject.
TView is found in VIEWS.TPU, it has 11 fields, including size and options,
and 64 methods, including Init, Done, Draw, Show and WriteLine (pages
306-321).
TGroup is also in VIEWS.TPU, it has 4 fields and 29 methods (pages
235-244).
Because units are used, it follows that there must be a USES statement at
the start of any application program to ensure that all the required TPUs
are called. Chapter 12 'Unit cross reference' (pages 189-204) gives
details of all the units used by Turbo Vision. Types, constants,
variables, procedures and functions are listed for each unit.
Because of inheritance, it is possible that a method used by any object
type may not be its own, but that of an ancestor type. It may therefore be
necessary to refer back through the hierarchy to find the definition of a
particular method.
TPoint is a simple object type representing a point on the screen by its
only two fields X and Y. It has no methods and is thus only a record and is
the ultimate abstraction as far as screen display is concerned.
TRect has two fields, A and B, both of type TPoint and 9 methods.
Apart from the standard object hierarchy of Turbo Vision, there are a
number of other elements (types, constants, variables, procedures and
functions) which are defined in the Turbo Vision units. These are listed
in Chapter 14, 'Global reference' on pages 327-384 and include for example:
TYPE PString defines a pointer to a string OBJECTS.TPU
PtrRec record of ofs & seg of a pointer OBJECTS.TPU
CONSTANT hcXXXX help context constants VIEWS.TPU
ofXXXX options flags VIEWS.TPU
VARIABLE ScreenHeight height in lines of current screen DRIVERS.TPU
MenuBar stores a pointer to menu bar APP.TPU
PROCEDURE DisposeMenu disposes all elements of the menu OBJECTS.TPU
ClearScreen clears the screen DRIVERS.TPU
FUNCTION NewStatusDef returns a pointer to a new
TStatusDef record MENUS.TPU
Turbo Vision examples.
----------------------
Now that the structure of Turbo Vision and the notation has been
presented, it is possible to proceed with discussion of a specific example,
which relates to a screen display like that of the Turbo Pascal Integrated
Development Environment. The display has a working area called the
Desktop, which occupies most of the screen, a Menu Bar at the top and a
Status Line at the bottom, which provides the user with advice on how to
proceed, even if it is only - Alt-X Exit.
The example is described in detail in Chapter 2 of the Turbo Vision Guide
(pages 23- 28). The program is in TVGUID01.PAS which is included with the
demo programs on the distribution disks and is listed below:
PROGRAM TFirst;
USES App; { application objects are in APP.TPU }
TYPE TMyApp = OBJECT(TApplication) { define new application type leaving }
END; { room for future expansion }
VAR MyApp : TMyApp; { create an instance of the new type }
BEGIN
MyApp.Init { set it up }
MyApp.Run { interact with the user